<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var minimumSize = function (nums, maxOperations) {
      let l = 0, r = 0;
      // 计算二分查找上边界r
      for (let n of nums) {
        r = Math.max(n, r);
      }
      // 注意二分边界条件
      while (l + 1 < r) {
        // JS语言特性：注意Math.floor向下取整
        let mid = Math.floor(l + (r - l) / 2), tmp = 0;
        for (let n of nums) {
          tmp += Math.floor((n - 1) / mid);
        }
        // 当前没有用完操作次数，说明还可以进一步降低最终的最小取值，向下调整上边界
        if (tmp <= maxOperations) {
          r = mid;
        }
        // 当前用完了操作次数，说明当前最小取值无法满足条件，向上调整下边界
        else {
          l = mid;
        }
      }
      // 注意最终返回上边界的值
      return r;
    };
    console.log(minimumSize(nums = [9], maxOperations = 2))
  </script>
</body>

</html>